<?php

/**
 *		//T基本函数//
 *		//这是一份试验品，由大街编写（zhongmingzi@gmail.com）
 *		//本程序默认环境：Zend Optimizer Yes / 3.3.3
 *		//		Apache/2.0.63 (Win32) PHP/5.2.12
 *		//		MySQL 支持 Yes / client lib version 5.0.89
 *		//		GD library Yes / bundled (2.0.34 compatible)
 *		//		eAccelerator/Memcache/xcache Yes
 *		//		cURL support enabled
 *		//时间：2010 10 16 04:01:07//
 */
if(!defined('IN')) {
	exit('Access Denied');
}

function sendtext($text, $uid, $replyid = 0) {
	global $_G;
	if(empty($text) || empty($uid)) return -1;
	$type = array(
		1 => '网页',
		2 => '手机',
	);
	$data = array(
		'uid' => $uid,
		'content_body' => $text,
		'dateline' => TIMESTAMP,
		'type' => $type[1],
	);

	if($replyid != 0) $data['replyid'] = (int)$replyid;
	if(DB::insert('t_content', $data) == 1) {
		!$replyid && DB::update('u_members_pro', array('status' => $text), "uid = $uid");
		$replyid && DB::operation('t_content', 'replytimes', "cid = $replyid");
		return 1;
	}
	else return 0;
}

function viewls($uid, $page, $limit = 20) {
	global $_G;
	$sql = "SELECT u.username, c.* FROM ".DB::t('t_content')." c LEFT JOIN ".DB::t('u_members')." u  USING(uid) WHERE uid = '$uid' AND c.replyid = 0";
	$return['page'] = prepage($page, $limit, 0, $sql);
	$sqladd = " ORDER BY dateline DESC LIMIT {$return['page']['offset']}, $limit";
	
	$q = DB::query($sql.$sqladd);
	while($v = DB::fetch($q)) {
		if($v['replytimes'] == 0) $v['replytimes'] = '';
		$return['data'][] = $v;
	}
	return $return;
}

function viewnode($cid, $page, $limit = 20) {
	global $_G;
	$cid = (int)$cid;
	$return['data']['first'] = DB::fetch_first("SELECT u.username, c.* FROM ".DB::t('t_content')." c LEFT JOIN ".DB::t('u_members')." u  USING(uid) WHERE c.cid = $cid");
	$sql = "SELECT u.username, c.* FROM ".DB::t('t_content')." c LEFT JOIN ".DB::t('u_members')." u  USING(uid) WHERE c.replyid = $cid";
	$return['page'] = prepage($page, $limit, 0, $sql);
	$sqladd = " ORDER BY dateline DESC LIMIT {$return['page']['offset']}, $limit";
	
	$q = DB::query($sql.$sqladd);
	while($v = DB::fetch($q)) {
		if($v['replytimes'] == 0) $v['replytimes'] = '';
		$return['data']['reply'][] = $v;
	}
	return $return;
}
